package com.zhika.zishi.fragments;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import com.zhika.zishi.R;
import com.zhika.zishi.adapter.MySelfLDAdapter;
import com.zhika.zishi.adapter.MySelfSPAdapter;
import com.zhika.zishi.beans.MySelfSPBean;
import com.zhika.zishi.constant.OthersConstant;
import com.zhika.zishi.util.LogUtil;

import java.util.ArrayList;

/**
 * Created by shi-02 on 2015/4/14.
 * 在个人主页中，攻略、提问、关注、草稿共用的fragment
 */
public class MySelfSPLDFragment extends Fragment {

    private final String TAG = "MySelfSPFragment";

    private View view;

    private Context context;

    private ListView listView;

    private ArrayList<MySelfSPBean> mySelfSPList = new ArrayList<>();

    private MySelfSPAdapter mySelfSPAdapter;

    private MySelfLDAdapter mySelfLDAdapter;
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.myself_fragment_layout,container,false);
        initView();
        return view;
    }

    private void initView(){

        context = getActivity();
        listView =(ListView) view.findViewById(R.id.myself_fragment_list_view);

        Bundle bundle = getArguments();
        if (bundle!=null){
            mySelfSPList = (ArrayList<MySelfSPBean>) bundle.getSerializable(OthersConstant.KEY_2);
            String type = bundle.getString(OthersConstant.MYSELF_TYPE);
            if (type.equals("strategy")||type.equals("problem")){
                mySelfSPAdapter = new MySelfSPAdapter(context,mySelfSPList);
                listView.setAdapter(mySelfSPAdapter);
            }else {
                mySelfLDAdapter = new MySelfLDAdapter(context,mySelfSPList);
                listView.setAdapter(mySelfLDAdapter);
            }
        }else {
            LogUtil.e(TAG,"bundle是空的");
        }



        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(context,"被点击了",Toast.LENGTH_SHORT).show();
            }
        });

    }

}
